/*    */ package com.cr.web.controller.system;
/*    */ 
/*    */ import com.cr.common.core.controller.BaseController;
/*    */ import com.google.code.kaptcha.Producer;
/*    */ import java.awt.image.BufferedImage;
/*    */ import java.io.IOException;
/*    */ import java.io.OutputStream;
/*    */ import javax.annotation.Resource;
/*    */ import javax.imageio.ImageIO;
/*    */ import javax.servlet.ServletOutputStream;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import javax.servlet.http.HttpSession;
/*    */ import org.springframework.stereotype.Controller;
/*    */ import org.springframework.web.bind.annotation.GetMapping;
/*    */ import org.springframework.web.bind.annotation.RequestMapping;
/*    */ import org.springframework.web.servlet.ModelAndView;
/*    */ 
/*    */ @Controller
/*    */ @RequestMapping({"/captcha"})
/*    */ public class SysCaptchaController extends BaseController {
/*    */   @Resource(name = "captchaProducer")
/*    */   private Producer captchaProducer;
/*    */   
/*    */   @Resource(name = "captchaProducerMath")
/*    */   private Producer captchaProducerMath;
/*    */   
/*    */   @GetMapping({"/captchaImage"})
/*    */   public ModelAndView getKaptchaImage(HttpServletRequest request, HttpServletResponse response) {
/* 40 */     ServletOutputStream out = null;
/*    */     try {
/* 43 */       HttpSession session = request.getSession();
/* 44 */       response.setDateHeader("Expires", 0L);
/* 45 */       response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
/* 46 */       response.addHeader("Cache-Control", "post-check=0, pre-check=0");
/* 47 */       response.setHeader("Pragma", "no-cache");
/* 48 */       response.setContentType("image/jpeg");
/* 50 */       String type = request.getParameter("type");
/* 51 */       String capStr = null;
/* 52 */       String code = null;
/* 53 */       BufferedImage bi = null;
/* 54 */       if ("math".equals(type)) {
/* 56 */         String capText = this.captchaProducerMath.createText();
/* 57 */         capStr = capText.substring(0, capText.lastIndexOf("@"));
/* 58 */         code = capText.substring(capText.lastIndexOf("@") + 1);
/* 59 */         bi = this.captchaProducerMath.createImage(capStr);
/* 61 */       } else if ("char".equals(type)) {
/* 63 */         capStr = code = this.captchaProducer.createText();
/* 64 */         bi = this.captchaProducer.createImage(capStr);
/*    */       } 
/* 66 */       session.setAttribute("KAPTCHA_SESSION_KEY", code);
/* 67 */       out = response.getOutputStream();
/* 68 */       ImageIO.write(bi, "jpg", (OutputStream)out);
/* 69 */       out.flush();
/* 72 */     } catch (Exception e) {
/* 74 */       e.printStackTrace();
/*    */     } finally {
/*    */       try {
/* 80 */         if (out != null)
/* 82 */           out.close(); 
/* 85 */       } catch (IOException e) {
/* 87 */         e.printStackTrace();
/*    */       } 
/*    */     } 
/* 90 */     return null;
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\system\SysCaptchaController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */